<?php
session_start();
include "../_init_.php";
include(constant('PATH_INCLUDE').'/class.uploadhelper.php');
$action= isset($_REQUEST["action"])?$_REQUEST["action"]:'';
$path = '';
switch($action)
{
	case 'save':
		$uploadDir = '/upload/';
		$path = UploadHelper::uploadImage('summaryimage',$uploadDir);
		$path = constant('SITE_URL_PATH').$path;
	break;
}
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="javascript">
	function check(form1){
		if(form1.image.value==""){
			alert("請選擇圖片!");
			return false;		
		}
	}
	function copyToClipBoard(){
    var clipBoardContent= document.getElementById('textimgurl').text;
   setCopy(clipBoardContent);
    alert("複製成功！");
    return false;
} 
function setCopy(_sTxt){
try{
if(window.clipboardData) {
    window.clipboardData.setData("Text", _sTxt);
} else if(window.netscape) {
    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
    var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
    if(!clip) return;
    var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
    if(!trans) return;
    trans.addDataFlavor('text/unicode');
    var str = new Object();
    var len = new Object();
    var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
    var copytext = _sTxt;
    str.data = copytext;
    trans.setTransferData("text/unicode", str, copytext.length*2);
    var clipid = Components.interfaces.nsIClipboard;
    if (!clip) return false;
    clip.setData(trans, null, clipid.kGlobalClipboard);
}
}catch(e){}
}
</script>
</head>
<body>
<div>上傳圖片然後複製圖片連接</div>
<br>
<FORM   method="post" name="form1"  onsubmit="return check(this);" enctype="multipart/form-data" >
<input type="hidden" name="action" value="save"/>
<input name="summaryimage" type="file"  size="15" maxlength="20">&nbsp;<INPUT type=submit    name=Submit2 value="上傳"/>
<br>
<input type="text" id="textimgurl" value="<?php echo $path;?>" style="width:600px;"/><input type="button" value="複製圖片地址" onclick="return copyToClipBoard();"/>
</FORM>
</body>
</html>